﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

using PowerCreator.LMS.CMS.Entity;
using PowerCreator.LMS.Web.NetMeeting;
using PowerCreator.LMS.NetMeeting.Entity;
using PowerCreator.LMS.Common.Script;

public partial class sysadmin_NetMeetingManager_AddMediaServer : PowerCreator.LMS.Web.Base.BasePage
{
    ManagerNetMeeting objManagerNetMeeting = new ManagerNetMeeting();
    LogicServer.NetMeetingClass objNetMeetingClass = new LogicServer.NetMeetingClass();
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (IsLicensed(PowerCreator.LMS.Action.Core.ActionInfo.AddJob))
        //{
        //    Script.RedirectURL(GetRefUrl());
        //}
        if (!IsPostBack)
        {
            InitPage();

            int MediaServerID = 0;
            if (Request.QueryString["MediaServerID"] != null)
            {
                MediaServerID = int.Parse(Request.QueryString["MediaServerID"].ToString());
                ViewState["MediaServerID"] = MediaServerID.ToString();
                BinderForm(MediaServerID);
            }


        }
    }
    protected override void InitPage()
    {

        btnSave.Text = "保存"; //GetLanageValueByKey("btn_Save", PowerCreator.LMS.Language.LanagetItemType.Page);
        btnReset.Text ="返回";// GetLanageValueByKey("btn_Reset", PowerCreator.LMS.Language.LanagetItemType.Page);
        base.InitPage();
    }



    private void BinderForm(int id)
    {

        TMediaServer vo = new TMediaServer();
        vo = objManagerNetMeeting.LoadTMediaServer(id);
        txt_IP.Text = vo.IP;
        txt_Port.Text = vo.Port.ToString();
       

    }
    private bool CheckPageData()
    {

        if (!PowerCreator.LMS.Common.Utils.PageValidate.IsNumber(txt_Port.Text.Trim()))
        {
            
            lbl_AddNew_msg_Port.Text = "请输入整数";
            return false;
        }

        return true;
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (!CheckPageData()) return;
        TMediaServer vo = new TMediaServer();
        if (ViewState["MediaServerID"] != null)
        {
            vo = objManagerNetMeeting.LoadTMediaServer(int.Parse(ViewState["MediaServerID"].ToString()));
        }
        vo.IP = txt_IP.Text.Trim();
        vo.Port = int.Parse(txt_Port.Text.Trim());



        if (ViewState["MediaServerID"] == null)
        {
            int MediaServerID=objManagerNetMeeting.AddNewTMediaServer_ReturnID(vo);
            if (MediaServerID>0)
            {

                objNetMeetingClass.WebAddMediaServer(MediaServerID, vo.IP, vo.Port);
                string url = "ManagerMediaServer.aspx";
                Script.RedirectURL(url);
            }
        }
        else
        {
            if (objManagerNetMeeting.UpdateTMediaServer(vo))
            {
                
                objNetMeetingClass.WebModifyMediaServer(vo.MediaServerID, vo.IP, vo.Port);
                string url = "ManagerMediaServer.aspx";
                Script.RedirectURL(url);
            }
        }
    }


    protected void btnReset_Click(object sender, EventArgs e)
    {
        string url = "ManagerMediaServer.aspx";
        Script.RedirectURL(url);
    }
}
